/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-03-13
 * Time: 14:02
 */
public class test1 {
    /**
     *  LeetCode  135  分发糖果
     */

    public int candy(int[] ratings) {
        int n = ratings.length;
        // 用于记录每个孩子要给多少个糖果
        int[] left = new int[n];
        int ret = 0;
        for(int i=0;i<n;i++){
            if(i>0 && ratings[i]>ratings[i-1]){
                left[i] = left[i-1]+1;
            }else{
                left[i] = 1;
            }
        }
        int right = 0;
        for(int i=n-1;i>=0;i--){
            if(i<n-1 && ratings[i]>ratings[i+1]){
                right++;
            }else{
                right = 1;
            }
            ret += Math.max(left[i],right);
        }
        return ret;
    }
}
